import type { AddressParams } from '@/types/address'
import type { AddressItem } from '@/types/address'
import http from '@/utils/https'

/**
 * 添加收货地址
 * @param data 请求参数
 * @param { string } receiver - 收货人姓名
 * @param { string } contact - 联系方式
 * @param { string } provinceCode - 省份编码
 * @param { string } cityCode - 城市编码
 * @param { string } countyCode - 区/县编码
 * @param { string } address - 详细地址
 * @param { number } isDefault - 是否设为默认地址，1为是，0为否
 * @returns { Promise }
 */
export const postMemberAddressAPI = (data: AddressParams) => {
  return http<{ id: number }>({
    method: 'POST',
    url: '/member/address',
    data,
  })
}

/**
 * 获取收货地址列表
 * @returns { Promise }
 */
export const getMemberAddressAPI = () => {
  return http<AddressItem[]>({
    method: 'GET',
    url: '/member/address',
  })
}

/**
 * 获取收货地址详情
 * @param { string } id 地址id(路径参数)
 * @returns { Promise }
 */
export const getMemberAddressByIdAPI = (id: string) => {
  return http<AddressItem>({
    method: 'GET',
    url: `/member/address/${id}`,
  })
}

/**
 * 修改收货地址
 * @param { string } id 地址id(路径参数)
 * @param { AddressParams } data 表单数据(请求体参数)
 * @returns { Promise }
 */
export const putMemberAddressByIdAPI = (id: string, data: AddressParams) => {
  return http<{ id: string }>({
    method: 'PUT',
    url: `/member/address/${id}`,
    data,
  })
}

/**
 * 删除收货地址
 * @param { string } id 地址id(路径参数)
 * @returns { Promise }
 */
export const deleteMemberAddressByIdAPI = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/member/address/${id}`,
  })
}
